﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UEC.Modules.Configuration
{
    public class ProcessScriptCompare:IComparer<ProcessScript>
    {
        public int Compare(ProcessScript x, ProcessScript y) {
            if (x == null && y == null)
            {
                return 0;
            }

            if (x == null && y != null)
            {
                return -1;
            }
            
            if (x != null && y == null)
            {
                return 1;
            }

            if (x.Type == y.Type)
            {
                if (x.Weight > y.Weight)
                {
                    return 1;
                }
                else if (x.Weight < y.Weight)
                {
                    return -1;
                }
                return 0;
            }

            if (x.Type == ProcessScript.ScriptType.USER)
            {
                return 1;
            }
            else if (y.Type == ProcessScript.ScriptType.USER)
            {
                return -1;
            } else if (x.Type == ProcessScript.ScriptType.SYSTEM)
            {
                return 1;
            }
            else if (y.Type == ProcessScript.ScriptType.SYSTEM)
            {
                return -1;
            }
            else if (x.Type == ProcessScript.ScriptType.RUN_ONCE)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }
}
